# -*- coding: utf-8 -*-
import types

def appendMenu (menu, name, url):
	"""
		add a menu
	"""
	m = (name, {'url' : url, 'selected' : False, 'subMenu' : []})
	menu.append (m)
	return m


def appendSubmenu (mainMenu, menuTitle, subMenuTitle, url, selected = False):
	"""
		add a submenu in the given menu
	"""
	if type(menuTitle) == types.StringType:
		m = dict (mainMenu).get(menuTitle)['subMenu']
	else:
		print menuTitle
		m = menuTitle[1]['subMenu']
	s = {
			'title': subMenuTitle,
			'url': url,
			'selected': selected,
		}
	m.append (s)
	return s

def setLeftMenu (request, menu, title):
	"""
		Set the menu and the title
	"""
	request.session['profile']['leftMenu'] = menu
	request.session['profile']['leftMenuTitle'] = title

def clearLeftMenu (request):
	request.session['profile']['leftMenu'] = None
